package app.fitness.simplefragment;

import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import app.fitness.fragment.DashBoardDetailFragment;

import com.razerzone.android.fitness.R;

import de.passsy.holocircularprogressbar.HoloCircularProgressBar;

public class DashBoardDetailActiveMinsSimpleFragment extends Fragment {

	/**
	 * String section
	 */
	/**
	 * View section
	 */
	private static HoloCircularProgressBar holoCircularPb;
	public static LinearLayout mLlTimeDayMonthMonths;
	public static LinearLayout mLlTimeWeekly;
	public static LinearLayout mLlTimeYearly;
	public static TextView mTvCurrent;
	public static TextView mTvFirstDay;
	public static TextView mTvGoal;
	public static TextView mTvLastDay;
	public static TextView mTvMiddleDay;
	private static TextView mTvValuePercent;

	/**
	 * The others section
	 */

	/**
	 * Listener
	 */
	// private OnClickListener mListernerBack = new OnClickListener() {
	//
	// @Override
	// public void onClick(View v) {
	// Fragment mFm = new DashBoardFragment();
	// ActivityFitness.mFm.beginTransaction()
	// .replace(R.id.fr_content_activity_fitness, mFm)
	// .commitAllowingStateLoss();
	// }
	// };

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		/**
		 * Set Orientation for page
		 */
		getActivity().setRequestedOrientation(
				ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);

		View v = inflater.inflate(
				R.layout.simple_fragment_dashboard_detail_active_mins,
				container, false);

		initialVariables(v);
		initialData();

		return v;
	}

	/**
	 * Initialize methods
	 */

	private void initialData() {
		// mTvActivity.setText(R.string.active_mins_);

		/**
		 * Check Time Picker selection first, and then, Load data followed the
		 * selection
		 */
		// DashBoardDetailFragment.putData(getActivity(),
		// DashBoardDetailFragment.mViewPager.getCurrentItem());

		/**
		 * Check current time picker to decide show which time line below chart
		 */
		DashBoardDetailFragment.showTimeLine(getActivity());

		// Draw chart
		// drawChartView();

		/**
		 * Integrate with Data to show on the page
		 */
		setFitnessData();

		if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
			// Set value percent
			setCompletionPercent();
		}
	}

	private void initialVariables(View v) {
		if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
			holoCircularPb = (HoloCircularProgressBar) v
					.findViewById(R.id.circularProgressBar_in_simple_fragment_dashboard_detail_active_mins);
		}

		// mLl = (LinearLayout) v
		// .findViewById(R.id.ll_graph_in_simple_fragment_dashboard_detail_active_mins);
		mLlTimeDayMonthMonths = (LinearLayout) v
				.findViewById(R.id.ll_time_day_month_months_in_dashboard_detail_active_mins);
		mLlTimeWeekly = (LinearLayout) v
				.findViewById(R.id.ll_time_weekly_in_dashboard_detail_active_mins);
		mLlTimeYearly = (LinearLayout) v
				.findViewById(R.id.ll_time_year_in_dashboard_detail_active_mins);
		mTvCurrent = (TextView) v
				.findViewById(R.id.tv_current_in_simple_fragment_dashboard_detail_active_mins);
		mTvFirstDay = (TextView) v
				.findViewById(R.id.tv_first_day_in_dashboard_detail_active_mins);
		mTvGoal = (TextView) v
				.findViewById(R.id.tv_goal_in_simple_fragment_dashboard_detail_active_mins);
		mTvLastDay = (TextView) v
				.findViewById(R.id.tv_last_day_in_dashboard_detail_active_mins);
		mTvMiddleDay = (TextView) v
				.findViewById(R.id.tv_middle_day_in_dashboard_detail_active_mins);
		mTvValuePercent = (TextView) v
				.findViewById(R.id.tv_value_percent_in_simple_fragment_dashboard_detail_active_mins);
	}

	/**
	 * Basic methods
	 */

	// private List<double[]> getChartValue() {
	// /**
	// * Remain Records has not used
	// */
	//
	// List<double[]> mListValues = new ArrayList<double[]>();
	// mListValues.add(new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
	// return mListValues;
	// }

	public static void setCompletionPercent() {
		/**
		 * Set circle progress bar
		 */
		if (Integer.valueOf(mTvGoal.getText().toString()) != 0) {
			/**
			 * If Goal value was set != 0
			 */
			float value = Float.valueOf(mTvCurrent.getText().toString())
					/ Float.valueOf(mTvGoal.getText().toString());

			/**
			 * Set percent
			 */
			mTvValuePercent.setText(String.format("%.02f", 100 * value) + " %");

			/**
			 * Set circular progress bar
			 */
			if (100 * value > 100) {
				holoCircularPb.setProgress(1);
			} else {
				holoCircularPb.setProgress(value);
			}
		} else if (Integer.valueOf(mTvGoal.getText().toString()) == 0) {
			/**
			 * If Goal value was set = 0, set 100%
			 */
			holoCircularPb.setProgress(1);

			/**
			 * Set percent
			 */
			mTvValuePercent.setText("100%");
		}
	}

	public static void setFitnessData() {
		// mTvActivity.setText(R.string.active_mins_);
		// mTvCurrent.setText(DashBoard.mLL);
		// mTvGoal.setText(Goal.goal.getActiveMins().trim());
	}

	// private XYMultipleSeriesDataset setUpDatasetChartView() {
	// String[] titles = new String[] { "" };
	//
	// /**
	// * Get Values to draw on Chart
	// */
	// XYMultipleSeriesDataset mDataset = AbstractDemoChart.buildBarDataset(
	// titles, getChartValue());
	//
	// return mDataset;
	// }
	//
	// private XYMultipleSeriesRenderer setUpRenderChartView() {
	// int[] colors = new int[] { getResources().getColor(R.color.green_text) };
	// XYMultipleSeriesRenderer renderer = AbstractDemoChart
	// .buildBarRenderer(colors);
	//
	// renderer.setAntialiasing(true);
	// renderer.setAxesColor(Color.BLACK);
	// renderer.setBarSpacing(4f);
	// renderer.setGridColor(Color.BLACK);
	// renderer.setMarginsColor(Color.argb(0x00, 0x01, 0x01, 0x01));
	// renderer.setShowGridX(true);
	// renderer.setPanEnabled(false);
	// renderer.setShowAxes(false);
	// renderer.setShowLegend(false);
	// renderer.setXLabels(0);
	// renderer.setYLabels(5);
	// renderer.setYLabelsColor(0, Color.TRANSPARENT);
	// renderer.setZoomEnabled(false, false);
	//
	// return renderer;
	// }
}
